<html>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>

<a href ="warehouseemployeemovebook.php" target = "_top">Make another move</a><br />

<?php
date_default_timezone_set('UTC');

$username="bsc353_4";
$password="sonbeans";
$database="bsc353_4";


$ISBN= $_POST['ISBN'];
$branchid= $_POST['branchid'];
$amount = $_POST['amount'];

if($amount <= 0)
{
  echo "Please select an amount more than 0";
}
else if($ISBN=="Select One"||$branchid=="Select One")
{
    echo"Error. Please select a value for ISBN and branchi ID";
}

else
{

    mysql_connect("clipper.encs.concordia.ca",$username,$password) or die ("Unable to connect to database");
    @mysql_select_db($database) or die ("Unable to select database");
    $warehousequery="Select * from BookInWarehouse where ISBN=$ISBN";
    $result=mysql_query($warehousequery);
    $quantity=intval(mysql_result($result,0,"quantity"));
    $checkstore= "Select ISBN from BookInStore where ISBN='$ISBN' and customerID is null"; 

    if($amount > $quantity)
        $amount = $quantity;
        
    

   // if(mysql_numrows($checkstore)==0)
   // {
   //     $addtoBookinStore="insert into BookInStore values('$ISBN',$amount,'$branchid','')";
   //     mysql_query($addtoBookinStore) or die("Could not add to BookInStore");
  //      $deleteware="delete from BookInWarehouse where ISBN='$ISBN'";
  //      mysql_query($deleteware) or die("Did not delete");
 //   }
   // else
  //  {
    $editBookinStore="update BookInStore set quantity=quantity + $quantity where ISBN='$ISBN'";
    mysql_query($editBookinStore) or die("Could not edit quantity in BookInStore");

    if($amount >= $quantity)
    {
        $deleteware="delete from BookInWarehouse where ISBN='$ISBN'";
        mysql_query($deleteware) or die("Did not delete");
    }
    else
    {
        $reduceware = "update BookInWarehouse set quantity= quantity-$amount where ISBN = '$ISBN';";
        mysql_query($reduceware) or die("Failed to reduce wares");
    }

  //  }

    mysql_close();

    //echo "query: $query \n"; 

    //mysql_query($updatequery) or die ("failed to add record");

    //$checkspecial="Select * from Orders where orderNumber=$ordernumber"; 
    //&addtobookinstore="Update ";


}

?> 
</html>
